// src/db.ts
import { DataSource } from 'typeorm';
import { SysUser } from './entity/SysUser';
import { AigcTask } from './entity/AigcTask';
import { AttributionPoint } from './entity/AttributionPoint';

export const AppDataSource = new DataSource({
    type: "mysql",
    host: process.env.DB_HOST,
    port: Number(process.env.DB_PORT),
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASE,
    entities: [SysUser, AigcTask, AttributionPoint],
    synchronize: false,
});

AppDataSource.initialize()
    .then(() => {
        console.log("Data Source has been initialized!" + process.env.DB_HOST);
    })
    .catch((err) => {
        console.error("Error during Data Source initialization", err);
    });